/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.minidota.jetty;

/**
 *
 * @author roman
 */
import com.minidota.game.Room;
import com.minidota.settings.Settings;
import com.minidota.utils.Util;
import java.io.IOException;
import java.util.Date;
import org.eclipse.jetty.server.*;
import org.eclipse.jetty.server.handler.HandlerCollection;
import org.eclipse.jetty.util.resource.FileResource;
import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.eclipse.jetty.websocket.server.WebSocketHandler;
import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory;

public class StartJetty {

    /**
     * Хранилище сервера Jetty
     */
    private static Server server = null;
    //private static GameWebSocketHandler gameWebSocketHandler=null;

    public static void main(String[] args) throws IOException, Exception {
        System.out.println(Util.DATE_FORMAT.format(new Date()) + " server start");
        start();
    }

    public static void start() {
        try {
            server = new Server(Settings.getInt("server.Port"));
            WebSocketHandler wsHandler = new WebSocketHandler() {
                @Override
                public void configure(WebSocketServletFactory factory) {
                    //factory.getPolicy().setIdleTimeout(500);
                    factory.register(GameWebSocket.class);
                }
            };
            server.setHandler(wsHandler);
            server.start();
            for (int i = 1; i <= 1; i++) {
                Room r = new Room();
                r.setId(i);
                Room.addNewRoom(r);
            }
            server.join();
        } catch (Exception ex) {
            System.out.println("StartJetty: " + ex.getMessage());
            //Logger.getLogger(StartJetty.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
